package org.rambadger.command.resource;

/**

 */
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.yammer.dropwizard.auth.Auth;
import com.yammer.dropwizard.views.View;
import org.rambadger.command.auth.AuthUser;
import org.rambadger.command.view.LoginView;

import java.util.Arrays;

@Path("/test/")
@Produces({MediaType.TEXT_HTML})
public class ViewMustacheTest {

    @Path("electricboogaloo")
    @GET
    public View LoginTest(@Auth(required = false) AuthUser user){
        if (user == null)
        return new LoginView();
        //return new StaticView2("not logged in");
        else
        return new StaticView2("you logged in " + user.getUsername() + " ");
    }
    @Path("{page}")
    @GET
    public View ViewTest(@PathParam("page") String page) {
        String[] allowedPages = new String[]{"tracks", "submissions", "badges",
                                "android", "ios", "linux", "osx", "windows",
                                "registerPlatform", "registerTrack","registerAssignment", "test"};


        if (Arrays.asList(allowedPages).contains(page))
        return new StaticView(page);

        else
        return new StaticNoMenu("404");
    }

}

class StaticView extends View{
    boolean area_home = true;
    String title = ": Testing ";
    String p_back = "}}";
    String p_front = "{{";
    public StaticView(String mustache){
        super("/"+mustache+".mustache");
        this.title = this.title + mustache;
    }
}
class StaticView2 extends View{
    String message = "";
    public StaticView2(String message){
        super("/test.mustache");
        this.message = message;
    }
}
class StaticNoMenu extends View{
    boolean area_home = true;
    String title = ": Testing ";
    boolean menu_hide = true;
    public StaticNoMenu(String mustache){
        super("/"+mustache+".mustache");
        this.title = this.title + mustache;
    }
}
